home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / prgs / Gfx / screenprint.b < prev    next >
Text File  |  1996-09-10  |  5KB  |  207 lines

  1. REM  ScreenPrint
  2. REM  Carolyn Scheppner   CBM  04/86
  3. REM
  4. REM  Graphic screen dump to the printer
  5. REM   using exec library calls
  6. REM  Requires exec.bmap
  7. REM  Use Preferences to select options
  8. REM   such as GrayScale and Negative
  9.  
  10. REM  ***  Calling Program  ***
  11.  
  12. REM  Custom Screen, some graphics
  13. w = 320: h = 200: d = 5
  14. SCREEN 1,w,h,d,1
  15. t$=" D = Draw   P = Print   Q = Quit "
  16. WINDOW 1,t$,(0,0)-(320,200),7,1
  17. PALETTE 0,1,1,1
  18. PALETTE 1,.2,.4,.8
  19.  
  20. GOSUB DrawLines:
  21.  
  22. MainLoop:
  23. k$ = INKEY$
  24. IF k$ = "d" THEN 
  25.    GOSUB DrawLines:
  26. ELSE
  27.   IF k$ = "p" THEN
  28.    BorderFlag% = 0  'No borders printed
  29.    GOSUB ScreenDump
  30.    BEEP  '..signal that we're done
  31.    REM  Time to read any error msgs
  32.    FOR de = 1 TO 5000: NEXT
  33.   ELSE
  34.     IF k$ = "q" THEN Quit
  35.   END IF
  36. END IF
  37. GOTO MainLoop
  38.  
  39. Quit:
  40. WINDOW CLOSE 1
  41. SCREEN CLOSE 1
  42. END
  43.  
  44. DrawLines:
  45. CLS               
  46. RANDOMIZE  TIMER
  47. FOR k = 1 TO 12
  48.    x1 = 80 + INT(RND(1) * (w - 160)) 
  49.    x2 = 80 + INT(RND(1) * (w - 160))
  50.    y1 = 40 + INT(RND(1) * (h - 100))
  51.    y2 = 40 + INT(RND(1) * (h - 100))
  52.    dx = 2 + INT(RND(1) * 3)
  53.    IF RND(1) < .5 THEN dx = -dx
  54.    dy = 2 + INT(RND(1) * 2)
  55.    IF RND(1) < .5 THEN dy = -dy
  56.    co = 1 + INT(RND(1) * 16)
  57.    nl = 12 + INT(RND(1) * 10) 
  58.    FOR j = 1 TO nl
  59.       LINE (x1,y1)-(x2,y2),co
  60.       x1 = x1 + dx
  61.       x2 = x2 + dx
  62.       y1 = y1 + dy
  63.       y2 = y2 - dy
  64.    NEXT
  65. NEXT
  66. RETURN
  67. END
  68.  
  69. ScreenDump:
  70.  
  71. REM  If first call of this routine 
  72. REM   declare the exec library functions
  73. REM    which return values
  74.  
  75. LIBRARY "exec.library"
  76.  
  77. DECLARE FUNCTION AllocSignal%() LIBRARY
  78. DECLARE FUNCTION AllocMem&()    LIBRARY
  79. DECLARE FUNCTION FindTask&()    LIBRARY
  80. DECLARE FUNCTION DoIO&()        LIBRARY
  81. DECLARE FUNCTION OpenDevice&()  LIBRARY
  82. DECLARE FUNCTION CloseDevice()  LIBRARY
  83. DECLARE FUNCTION FreeMem()      LIBRARY
  84. DECLARE FUNCTION FreeSignal()   LIBRARY
  85. DECLARE FUNCTION AddPort()      LIBRARY
  86. DECLARE FUNCTION RemPort()      LIBRARY
  87.  
  88. REM  Get addresses of the structures
  89.  
  90. sWindow&   = WINDOW(7)
  91. sScreen&   = PEEKL(sWindow& + 46)
  92. sViewPort& = sScreen& + 44
  93. sRastPort& = sScreen& + 84
  94. sColorMap& = PEEKL(sViewPort& + 4)
  95.  
  96. REM  Get Screen width, height, modes 
  97.  
  98. maxWidth%  = PEEKW(sScreen& + 12)
  99. maxHeight% = PEEKW(sScreen& + 14)
  100. viewModes% = PEEKW(sViewPort& + 32)
  101.  
  102. REM Set up parameters for dump command
  103.  
  104. command%  = 11   'Printer command number
  105. srcX% = 0        'Send whole screen
  106. srcY% = 0 
  107. srcWidth%  = maxWidth%
  108. srcHeight% = maxHeight%
  109. destRows& = 0    'Dump will compute
  110. destCols& = 0
  111. special% = &H84  'FullCol | Aspect
  112.  
  113. IF BorderFlag% = 0 THEN  'No Borders
  114.    srcX% = srcX% + 3
  115.    srcY% = srcY% + 11
  116.    srcWidth%  = srcWidth% - 3 - 11
  117.    srcHeight% = srcHeight% - 11 - 3
  118. END IF   
  119.  
  120. REM *** CreatePort ***
  121.  
  122. sigBit% =  AllocSignal%(-1)
  123. ClearPublic& = 65537&
  124. msgPort& = AllocMem&(40,ClearPublic&)
  125. IF msgPort& = 0 THEN
  126.    PRINT "Can't allocate msgPort"
  127.    GOTO cleanup4
  128. END IF
  129.  
  130. POKE(msgPort& + 8), 4 'Type=NT_MSGPORT
  131. POKE(msgPort& + 9), 0 'Priority 0 
  132. portName$ = "MyPrtPort"+CHR$(0)
  133. POKEL(msgPort& + 10), SADD(portName$)
  134. POKE(msgPort& + 14), 0 'Flags
  135. POKE(msgPort& + 15), sigBit%
  136. sigTask& = FindTask&(0)
  137. POKEL(msgPort& + 16), sigTask&
  138.  
  139. CALL AddPort(msgPort&)  'Add the port 
  140.  
  141. REM  *** CreatExtIO ***
  142.  
  143. ioRequest& = AllocMem&(64,ClearPublic&)
  144. IF ioRequest& = 0  THEN
  145.    PRINT "Can't allocate ioRequest"
  146.    GOTO cleanup3
  147. END IF
  148.  
  149. POKE(ioRequest& + 8),5 'Type=NT_MESSAGE
  150. POKE(ioRequest& + 9),0 'Priority 0
  151. POKEL(ioRequest& + 14), msgPort&
  152.  
  153.  
  154. REM  *** Open the Printer Device ***
  155.  
  156. devName$ = "printer.device"+CHR$(0)
  157. pError& = OpenDevice&(SADD(devName$),0,ioRequest&,0)
  158. 'pError& = OpenDevice&(devName$,0,ioRequest&,0)
  159. IF pError& <> 0  THEN
  160.    PRINT "Can't open printer"
  161.    GOTO cleanup2
  162. END IF
  163.  
  164. REM  *** Dump the RastPort ***
  165.  
  166. POKEW(ioRequest& + 28), command%
  167. POKEL(ioRequest& + 32), sRastPort&
  168. POKEL(ioRequest& + 36), sColorMap&
  169. POKEL(ioRequest& + 40), viewModes%
  170. POKEW(ioRequest& + 44), srcX%
  171. POKEW(ioRequest& + 46), srcY%
  172. POKEW(ioRequest& + 48), srcWidth%
  173. POKEW(ioRequest& + 50), srcHeight%
  174. POKEL(ioRequest& + 52), destCols&
  175. POKEL(ioRequest& + 56), destRows&
  176. POKEW(ioRequest& + 60), special%
  177.  
  178. ioError& = DoIO&(ioRequest&)
  179. IF ioError& <> 0 THEN
  180.    PRINT "DumpRPort error =" ioError&
  181.    GOTO cleanup1
  182. END IF
  183.  
  184. cleanup1:
  185.    REM  *** Close Printer Device ***
  186.    CALL CloseDevice(ioRequest&)
  187.  
  188. cleanup2:
  189.    REM  *** DeleteExtIO ***
  190.    POKE(ioRequest& + 8), &HFF
  191.    POKEL(ioRequest& + 20), -1
  192.    POKEL(ioRequest& + 24), -1
  193.    CALL FreeMem(ioRequest&,64)
  194.  
  195. cleanup3:
  196.    REM  *** DeletePort ***
  197.    CALL RemPort(msgPort&)
  198.    POKE(msgPort& + 8), &HFF  
  199.    POKEL(msgPort& + 20), -1
  200.    CALL FreeSignal(sigBit%)
  201.    CALL FreeMem(msgPort&,40)
  202.    
  203. cleanup4:   
  204.    LIBRARY CLOSE
  205.  
  206. RETURN
  207.